package solucionessgh.Util;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;

/**
 *
 * @author roderick
 */

/*
commons-beanutils
commons-collections
commons-digester
commons-javaflow
commons-logging
itext
jasperreports
jcommon
*/
public class Reporte {
    
    private String url;

    public Reporte(String url){
        this.url = url;
    }
    
    public void setVisible( ) throws ClassNotFoundException {
      //ExternalContext econtext = getExternalContext();
      InputStream inputStream = Reporte.class.getResourceAsStream(this.url);
      if (inputStream == null) {
          throw new ClassNotFoundException("Archivo "+this.url+".jasper no se encontró");
      }
      String url = "jdbc:postgresql://localhost/sgh";
      Connection con = null;
      try{
            Class.forName("org.postgresql.Driver");
            con = DriverManager.getConnection( url,"postgres","postgres");
      }
      catch( Exception e ){

        }

      try {        
          JasperPrint jasperPrint = JasperFillManager.fillReport(inputStream, null, con);
          JasperViewer m_Preview=new JasperViewer(jasperPrint, false);
            m_Preview.setVisible(true);

      } catch (Exception ex) {
          
      }


  }

    /*public static void main(String[] args) {
        Reporte rep = new Reporte("/Usuarios/ReporteUsuarios.jasper");
        try {
            rep.setVisible();
        } catch (ClassNotFoundException ex) {
            
        }
    }*/

}
